package com.ruoyi.system.controller.transport;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.db.transport.TransportTask;
import com.ruoyi.system.domain.dto.TransportTaskDto;
import com.ruoyi.system.domain.vo.PageInfo;
import com.ruoyi.system.service.OrderWarehouseStateService;
import com.ruoyi.system.utils.MyPageUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * 运输司机任务管理
 */
@RestController
@RequestMapping("/transport/driver")
public class TransportDriverController  extends BaseController {

    @Resource
    private OrderWarehouseStateService orderWarehouseStateService;
    /**
     * 列出司机的任务列表
     */
    @PreAuthorize("@ss.hasPermi('transport:driver:list')")
    @GetMapping("/list")
    public PageInfo<TransportTaskDto> list(TransportTask transportTask)
    {
        // startPage();
        return MyPageUtils.startPage((orderWarehouseStateService.listTransportTaskByDriverId(SecurityUtils.getUserId())));
    }

    /**
     * 获取运输任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('transport:driver:query')")
    @GetMapping()
    public AjaxResult getInfo(@RequestParam("taskId") Long taskId)
    {
        return AjaxResult.success(orderWarehouseStateService.getTransportTask(taskId));
    }

    /**
     * 设置运输任务状态(state = 2 是运输中 state = 3 是已完成)
     */
    @PreAuthorize("@ss.hasPermi('transport:driver:change')")
    @PutMapping()
    public AjaxResult changeState(@RequestParam("taskId") Long taskId, @RequestParam("state")  Integer state)
    {
        return toAjax(orderWarehouseStateService.changeTaskState(taskId,state));
    }





}
